home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / viewkit / VCal / TimeInterval.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.9 KB  |  185 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18. #include "TimeInterval.h"
  19. #include "TimeEntry.h"
  20. #include "TimeGrid.h"
  21. #include "Utils.h"
  22. #include <Xm/Form.h>
  23. #include <Xm/Label.h>
  24. #include <Xm/SeparatoG.h>
  25.  
  26. static int count;
  27. static Arg args[10];
  28.  
  29. TimeInterval::TimeInterval(const char *n, TimeGrid *grid)
  30. : VkComponent(n)
  31. {
  32.   _grid = grid;
  33.  
  34.   _start = 0;
  35.   _length = 0;
  36.   _callback = NULL;
  37.  
  38.   count = 0;
  39.   _baseWidget = XmCreateForm(_grid->getParent(), _name, args, count);
  40.   XtAddEventHandler(_baseWidget, ButtonPressMask, False,
  41.             TimeInterval::button_press, (XtPointer) this);
  42.  
  43.   count = 0;
  44.   XtSetArg(args[count], XmNtopAttachment, XmATTACH_FORM);  count++;
  45.   XtSetArg(args[count], XmNleftAttachment, XmATTACH_FORM);  count++;
  46.   XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM);  count++;
  47.   _startLabel = XmCreateLabel(_baseWidget, "startLabel", args, count);
  48.   XtManageChild(_startLabel);
  49.   XtAddEventHandler(_startLabel, ButtonPressMask, False,
  50.             TimeInterval::button_press, (XtPointer) this);
  51.  
  52.   count = 0;
  53.   XtSetArg(args[count], XmNbottomAttachment, XmATTACH_FORM);  count++;
  54.   XtSetArg(args[count], XmNleftAttachment, XmATTACH_FORM);  count++;
  55.   XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM);  count++;
  56.   _endLabel = XmCreateLabel(_baseWidget, "endLabel", args, count);
  57.   XtManageChild(_endLabel);
  58.   XtAddEventHandler(_endLabel, ButtonPressMask, False,
  59.             TimeInterval::button_press, (XtPointer) this);
  60.  
  61.   count = 0;
  62.   XtSetArg(args[count], XmNtopAttachment, XmATTACH_WIDGET);  count++;
  63.   XtSetArg(args[count], XmNtopWidget, _startLabel);  count++;
  64.   XtSetArg(args[count], XmNbottomAttachment, XmATTACH_WIDGET);  count++;
  65.   XtSetArg(args[count], XmNbottomWidget, _endLabel);  count++;
  66.   XtSetArg(args[count], XmNrightAttachment, XmATTACH_FORM);  count++;
  67.   XtSetArg(args[count], XmNorientation, XmVERTICAL);  count++;
  68.   _midSep = XmCreateSeparatorGadget(_baseWidget, "midSep", args, count);
  69.   XtManageChild(_midSep);
  70.  
  71.   count = 0;
  72.   XtSetArg(args[count], XmNheight, &_labelHeight);  count++;
  73.   XtGetValues(_startLabel, args, count);
  74.  
  75.   installDestroyHandler();
  76. }
  77.  
  78. TimeInterval::~TimeInterval()
  79. {
  80.   XtRemoveEventHandler(_baseWidget, ButtonPressMask, False,
  81.                TimeInterval::button_press, (XtPointer) this);
  82.   XtRemoveEventHandler(_startLabel, ButtonPressMask, False,
  83.                TimeInterval::button_press, (XtPointer) this);
  84.   XtRemoveEventHandler(_endLabel, ButtonPressMask, False,
  85.                TimeInterval::button_press, (XtPointer) this);
  86. }
  87.  
  88. /**********************************************************************/
  89.  
  90. const char *
  91. TimeInterval::className()
  92. {
  93.   return "TimeInterval";
  94. }
  95.  
  96. void
  97. TimeInterval::setTimeInterval(int start, int length)
  98. {
  99.   Position x, y;
  100.   Dimension width, height;
  101.   char str[256];
  102.   XmString xs;
  103.   Pixel bg;
  104.  
  105.   if (_start != start || _length != length) {
  106.     _start = start;
  107.     _length = length;
  108.     if (_grid->requestIntervalPosition(_start, _length, &x, &y,
  109.                        &width, &height)) {
  110.       if (height < 2*_labelHeight) {
  111.     count = 0;
  112.     XtSetArg(args[count], XmNheight, height);  count++;
  113.     XtSetValues(_startLabel, args, count);
  114.       } else {
  115.     count = 0;
  116.     XtSetArg(args[count], XmNheight, _labelHeight);  count++;
  117.     XtSetValues(_startLabel, args, count);
  118.       }
  119.       count = 0;
  120.       XtSetArg(args[count], XmNx, x);  count++;
  121.       XtSetArg(args[count], XmNy, y);  count++;
  122.       XtSetArg(args[count], XmNwidth, width);  count++;
  123.       XtSetArg(args[count], XmNheight, height);  count++;
  124.       XtSetValues(_baseWidget, args, count);
  125.       
  126.       count = 0;
  127.       XtSetArg(args[count], XmNbackground, &bg);  count++;
  128.       XtGetValues(_grid->getText()->baseWidget(), args, count);
  129.       count = 0;
  130.       XtSetArg(args[count], XmNbackground, bg);  count++;
  131.       XtSetValues(_baseWidget, args, count);
  132.  
  133.       formatShortTime(_start/60, _start%60, str);
  134.       xs = XmStringCreateSimple(str);
  135.       count = 0;
  136.       XtSetArg(args[count], XmNlabelString, xs);  count++;
  137.       XtSetArg(args[count], XmNfontList, _grid->getTextFontList());  count++;
  138.       XtSetArg(args[count], XmNbackground, bg);  count++;
  139.       XtSetValues(_startLabel, args, count);
  140.       
  141.       formatShortTime((_start+_length)/60, (_start+_length)%60, str);
  142.       xs = XmStringCreateSimple(str);
  143.       count = 0;
  144.       XtSetArg(args[count], XmNlabelString, xs);  count++;
  145.       XtSetArg(args[count], XmNfontList, _grid->getTextFontList());  count++;
  146.       XtSetArg(args[count], XmNbackground, bg);  count++;
  147.       XtSetValues(_endLabel, args, count);
  148.     }
  149.   }
  150.   if (XtWindow(_baseWidget)) {
  151.     XRaiseWindow(XtDisplay(_baseWidget), XtWindow(_baseWidget));
  152.   }
  153. }
  154.  
  155. void
  156. TimeInterval::setCallback(XtCallbackProc proc, XtPointer client_data)
  157. {
  158.   _callback = proc;
  159.   _callbackData = client_data;
  160. }
  161.  
  162. /**********************************************************************/
  163.  
  164. void
  165. TimeInterval::callCallback(TimeIntervalReason reason)
  166. {
  167.   if (_callback) {
  168.     (*_callback)(_baseWidget, _callbackData, (XtPointer) reason);
  169.   }
  170. }
  171.  
  172. /**********************************************************************/
  173.  
  174. void
  175. TimeInterval::button_press(Widget, XtPointer client_data, XEvent *event,
  176.                Boolean *)
  177. {
  178.   TimeInterval *obj = (TimeInterval *) client_data;
  179.  
  180.   if (event->xbutton.button == Button1) {
  181.     obj->callCallback(TI_deselect);
  182.   }
  183. }
  184.  
  185.